package com.sky.myapplication.java.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.sky.myapplication.R;

/**
 * Created by ruolan
 * Time 2021/6/18
 * Desc 查看activity的生命周期，启动，跳转，退到后台，结束
 */
public class ThreeActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv_log;
    private Button btn_back, btn_jump;
    private String log = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_another);
        tv_log = findViewById(R.id.tv_log);
        btn_back = findViewById(R.id.btn_back);
        btn_jump = findViewById(R.id.btn_jump);

        btn_jump.setText("跳转到新的上个页面");

        btn_back.setOnClickListener(this);
        btn_jump.setOnClickListener(this);
        //TextView 换行 \n
        log += "onCreate";
        tv_log.setText(log);

        Log.d("", "onCreate");

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_back:
                    finish();
                break;
            case R.id.btn_jump:
                Intent intent = new Intent(ThreeActivity.this, AnotherActivity.class);
                startActivity(intent);
            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        log += "\n onResume";
        tv_log.setText(log);
        Log.d("", "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();

        log += "\n onPause";
        tv_log.setText(log);
        Log.d("", "onPause");
    }

    @Override
    protected void onStart() {
        super.onStart();

        log += "\n onStart";
        tv_log.setText(log);
        Log.d("", "onStart");
    }

    @Override
    protected void onStop() {
        super.onStop();

        log += "\n onStop";
        tv_log.setText(log);
        Log.d("", "onStop");
    }

    @Override
    protected void onRestart() {
        super.onRestart();

        log += "\n onRestart";
        tv_log.setText(log);
        Log.d("", "onRestart");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        log += "\n onDestroy";
        tv_log.setText(log);
        Log.d("", "onDestroy");
    }
}
